<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
    <ant-simple-table :api="getGatewayRoutes">
        <!-- 表头操作按钮 -->
        <template v-slot:headerOperators="">
            <a-button icon="plus" type="primary" @click="() => $router.push({ name : 'addRoute' })">新增</a-button>
        </template>
        <!-- 表格列 -->
        <template v-slot:tableColumns="">
            <a-table-column title="编号" dataIndex="id" :align="'center'" />
            <a-table-column title="路由名称" dataIndex="routeName" :align="'center'" />
            <a-table-column title="路径" dataIndex="uri" :align="'center'" />
            <a-table-column title="创建时间" dataIndex="createTime" :align="'center'" />
            <a-table-column title="操作">
                <template slot-scope="record">
                    <template>
                        &nbsp;
                        <router-link :to='{ name : "editRoute",params : { routeId : record.id } }'>修改</router-link>
                        &nbsp;
                    </template>
                    <template>
                        &nbsp;
                        <a href="javascript:void(0);" @click="deleteRoute(record.id)">删除</a>
                        &nbsp;
                    </template>
                </template>
            </a-table-column>
        </template>

        <!-- 抽屉 -->
        <ant-drawer route-name="dynamicRoute" />
    </ant-simple-table>
</template>

<script>
    import AntSimpleTable from '../../components/table/AntSimpleTable';
    import AntDrawer from '../../components/drawer/AntDrawer';
    import { getGatewayRoutes,deleteGatewayRoute } from '../../apis/system';
    export default {
        components : { AntSimpleTable,AntDrawer },
        methods : {
            /**
             * 获取网关路由列表
             */
            getGatewayRoutes,
            /**
             * 根据Id删除路由
             * @param routeId
             */
            deleteRoute : function (routeId) {
                let $this = this;
                deleteGatewayRoute(routeId).then(() => {
                    $this.$message.success("删除成功").then();
                    $this.$router.push({
                        name : 'dynamicRoute',
                        query : { reload : new Date().getTime().toString() }
                    }).then();
                });
            } ,
        }
    }
</script>
